package com.android.baseconfig.data.http.okhttp.interceptor;

/**
 * ---------------------------------------------------------------- <br>
 * Copyright (C) 2014-2020, by het, Shenzhen, All rights reserved.  <br>
 * ---------------------------------------------------------------- <br>
 * <p>
 * 描述: 动态设置接口请求超时时间 <br>
 * 作者: lei <br>
 * 日期: 2019/3/29 <br>
 */

import com.android.baseconfig.data.http.okhttp.util.TimeOut;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

public class DynamicTimeoutInterceptor implements Interceptor {

    @Override
    public Response intercept(Chain chain) throws IOException {
        Request request = chain.request();
        String requestUrl = request.url().toString();
        boolean isPrivacyApi = requestUrl.contains("possTAgreement/page");
        if (isPrivacyApi){
            return chain.withConnectTimeout(TimeOut.PRIVACY_CONNECT, TimeUnit.SECONDS)
                    .withWriteTimeout(TimeOut.PRIVACY_READ,TimeUnit.SECONDS)
                    .withReadTimeout(TimeOut.PRIVACY_READ,TimeUnit.SECONDS)
                    .proceed(request);
        }
        return chain.proceed(request);
    }
}
